<!--_meta 作为公共模版分离出去-->
@include('admin.header')
<link href="/static/admin/css/H-ui.min.css" rel="stylesheet">
<link href="/static/admin/css/H-ui.admin.css" rel="stylesheet">
<link href="/static/admin/css/iconfont.css" rel="stylesheet">
<link href="/static/admin/css/skin.css" rel="stylesheet">
<link href="/static/admin/css/style.css" rel="stylesheet">
<link href="/static/admin/css/zTreeStyle.css" rel="stylesheet">
	<style>
		.select-class{
			width: 50%;
		}
		.parent {
			float: left;
			display: block;
		}
		.edit-msg {
			margin-left: 40px;
			width: 50px;
			border: 1px solid #ccc;
			border-radius: 0.5rem;
			text-align: center;
			background: bisque;
			cursor: pointer;
		}
        #file-box,.file-pic{
            display: inline-block;
            width: 17%;
            height: 120px;
            padding: 1% .5%;
            text-align: center;
            margin: 2px;
            position: relative;

        }
        .release-pic{font-size: 15px;}
        .release-pic p {
            margin-top: 1em;
            color: darkgrey;
        }
        .file-pic img{width: 100%;height: 100%;}
        .file-pic .ap-del{
            position: absolute;
            top: -6px;
            right: 4px;
            background-color: firebrick;
            color: #fff;
            width: 16px;
            height: 14px;
            font-size: 10px;
            line-height: 10px;
            text-align: center;
        }
        .formControls{
            overflow: hidden;
        }
        .formControls .soon{
            float: left;
            width:calc(25% - 30px);
            margin-left: 30px;
            margin-top: 5px;
        }
	</style>
<!--[if IE 6]>
<script type="text/javascript" src="__PUBLIC__/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->

<link href="__PUBLIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page-container">
		<ul class="nav nav-tabs">
			<li><a href="/group/groupList">用户组列表</a></li>
			<li  class="active"><a href="javascript:void(0)" target="_self">@if($id > 0) 编辑用户组 @else 添加用户组 @endif</a></li>
		</ul>
	<form method="post" class="form form-horizontal js-category-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户组名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="title" value="@if($id>0){{{$group->title}}} @endif" id="" placeholder="请输入用户组名称"  style="width:50%">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户组状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="radio" value="1" name="status" @if($id>0){@if($group->status == 1 ){echo checked='checked';}@endif} @endif />正常
                <input type="radio" value="0" name="status" style="margin-left: 10px;" />禁用
            </div>
        </div>
        @foreach($category as $key => $val)
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">@if($key ==1 )<span class="c-red">*</span>用户组权限：@endif</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <div class="parent-list"><input type="checkbox" value="{{$val->id}}" name="rules[]" class="rule-parent" @if($id>0){@if(in_array($val->id,$info['rules'])){echo checked='checked';}@endif}@endif />{{$val->title}}</div>
                     @foreach($val->child as $key => $v)
                        <div class="soon"><input type="checkbox" value="{{$v->id}}" name="rules[]" class="rule-son" @if($id>0){@if(in_array($v->id,$info['rules'])){echo checked='checked';}@endif}@endif/>{{$v->title}}</div>
                      @endforeach
                </div>
        </div>
		@endforeach
		<div class="row cl">
			<div class="form-actions">
				<input type="hidden" name="id" value="{{$id or 0}}"/>
				<input type="hidden" name="_token"  value="{{csrf_token()}}"/>
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn btn-primary js-ajax-submit" href="{{asset('admin/adminList')}}">返回</a>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/js/validate/validate.js"></script>
<script type="text/javascript" src="/static/js/layer/layer.js"></script>
<script type="text/javascript" src="/static/js/ajaxfileupload.js"></script>
<script type="text/javascript">

  $(function(){

  		$('.rule-parent').bind('click',function(){
		        if($(this).is(':checked')){
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',true);
		        }else{
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',false);
		        }
		 	  });

		    $('.rule-son').bind('click',function(){
		        var checkLenth = $(this).parent().siblings('.soon').children('input[name="rules[]"]:checked').length;
		        if(!$(this).is(':checked') && checkLenth == 0){
		            $(this).parent().siblings('.parent-list').children('.rule-parent').prop('checked',false);
		        }else{
		            $(this).parent().siblings('.parent-list').children('.rule-parent').prop('checked',true);
		        }
		    });
		    

  				$(".js-category-add").validate({
				rules: {
					title: {
						required: true
					}
				},
				messages: {
					title: {
						required: "用户组不能为空"
					}
				},

				submitHandler: function () {

					$.post("/group/group{{$action}}",$('.js-category-add').serialize(), function (msg) {
						if (msg.status == 1) {
							layer.confirm(msg.info, {
								btn: ['确定']
							}, function(){
								@if($action == 'Add')
									window.location.href="{{asset('group/groupList')}}";
								@else
									window.location.href="{{asset('group/groupList')}}";
								@endif
							});
						} else {
							showMsg(msg.info);
						}
					}, 'json');
					return false;
				}
			});

		 
  });

  	   /**
		 * layer提示
		 */
		function showMsg(msg){
			layer.alert(msg, {
				title: '提示',
				icon: 2,
			});
		}

</script>
</body>
</html>